using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the LockX class.
	/// </summary>
    [Serializable]
	public partial class LockXCollection : ActiveList<LockX, LockXCollection>
	{	   
		public LockXCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>LockXCollection</returns>
		public LockXCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                LockX o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Lock table.
	/// </summary>
	[Serializable]
	public partial class LockX : ActiveRecord<LockX>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public LockX()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public LockX(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public LockX(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public LockX(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Lock", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarLockId = new TableSchema.TableColumn(schema);
				colvarLockId.ColumnName = "LockId";
				colvarLockId.DataType = DbType.Guid;
				colvarLockId.MaxLength = 0;
				colvarLockId.AutoIncrement = false;
				colvarLockId.IsNullable = false;
				colvarLockId.IsPrimaryKey = true;
				colvarLockId.IsForeignKey = false;
				colvarLockId.IsReadOnly = false;
				colvarLockId.DefaultSetting = @"";
				colvarLockId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLockId);
				
				TableSchema.TableColumn colvarLockObject = new TableSchema.TableColumn(schema);
				colvarLockObject.ColumnName = "LockObject";
				colvarLockObject.DataType = DbType.Guid;
				colvarLockObject.MaxLength = 0;
				colvarLockObject.AutoIncrement = false;
				colvarLockObject.IsNullable = false;
				colvarLockObject.IsPrimaryKey = false;
				colvarLockObject.IsForeignKey = false;
				colvarLockObject.IsReadOnly = false;
				colvarLockObject.DefaultSetting = @"";
				colvarLockObject.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLockObject);
				
				TableSchema.TableColumn colvarTransaction = new TableSchema.TableColumn(schema);
				colvarTransaction.ColumnName = "Transaction";
				colvarTransaction.DataType = DbType.Guid;
				colvarTransaction.MaxLength = 0;
				colvarTransaction.AutoIncrement = false;
				colvarTransaction.IsNullable = false;
				colvarTransaction.IsPrimaryKey = false;
				colvarTransaction.IsForeignKey = false;
				colvarTransaction.IsReadOnly = false;
				colvarTransaction.DefaultSetting = @"";
				colvarTransaction.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTransaction);
				
				TableSchema.TableColumn colvarActivationDate = new TableSchema.TableColumn(schema);
				colvarActivationDate.ColumnName = "ActivationDate";
				colvarActivationDate.DataType = DbType.DateTime;
				colvarActivationDate.MaxLength = 0;
				colvarActivationDate.AutoIncrement = false;
				colvarActivationDate.IsNullable = true;
				colvarActivationDate.IsPrimaryKey = false;
				colvarActivationDate.IsForeignKey = false;
				colvarActivationDate.IsReadOnly = false;
				colvarActivationDate.DefaultSetting = @"";
				colvarActivationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarActivationDate);
				
				TableSchema.TableColumn colvarUserInfo = new TableSchema.TableColumn(schema);
				colvarUserInfo.ColumnName = "UserInfo";
				colvarUserInfo.DataType = DbType.String;
				colvarUserInfo.MaxLength = 256;
				colvarUserInfo.AutoIncrement = false;
				colvarUserInfo.IsNullable = true;
				colvarUserInfo.IsPrimaryKey = false;
				colvarUserInfo.IsForeignKey = false;
				colvarUserInfo.IsReadOnly = false;
				colvarUserInfo.DefaultSetting = @"";
				colvarUserInfo.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserInfo);
				
				TableSchema.TableColumn colvarLastCall = new TableSchema.TableColumn(schema);
				colvarLastCall.ColumnName = "LastCall";
				colvarLastCall.DataType = DbType.DateTime;
				colvarLastCall.MaxLength = 0;
				colvarLastCall.AutoIncrement = false;
				colvarLastCall.IsNullable = true;
				colvarLastCall.IsPrimaryKey = false;
				colvarLastCall.IsForeignKey = false;
				colvarLastCall.IsReadOnly = false;
				colvarLastCall.DefaultSetting = @"";
				colvarLastCall.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastCall);
				
				TableSchema.TableColumn colvarNextCall = new TableSchema.TableColumn(schema);
				colvarNextCall.ColumnName = "NextCall";
				colvarNextCall.DataType = DbType.DateTime;
				colvarNextCall.MaxLength = 0;
				colvarNextCall.AutoIncrement = false;
				colvarNextCall.IsNullable = true;
				colvarNextCall.IsPrimaryKey = false;
				colvarNextCall.IsForeignKey = false;
				colvarNextCall.IsReadOnly = false;
				colvarNextCall.DefaultSetting = @"";
				colvarNextCall.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNextCall);
				
				TableSchema.TableColumn colvarUltimatum = new TableSchema.TableColumn(schema);
				colvarUltimatum.ColumnName = "Ultimatum";
				colvarUltimatum.DataType = DbType.Int32;
				colvarUltimatum.MaxLength = 0;
				colvarUltimatum.AutoIncrement = false;
				colvarUltimatum.IsNullable = false;
				colvarUltimatum.IsPrimaryKey = false;
				colvarUltimatum.IsForeignKey = false;
				colvarUltimatum.IsReadOnly = false;
				colvarUltimatum.DefaultSetting = @"";
				colvarUltimatum.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUltimatum);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Lock",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("LockId")]
		[Bindable(true)]
		public Guid LockId 
		{
			get { return GetColumnValue<Guid>(Columns.LockId); }
			set { SetColumnValue(Columns.LockId, value); }
		}
		  
		[XmlAttribute("LockObject")]
		[Bindable(true)]
		public Guid LockObject 
		{
			get { return GetColumnValue<Guid>(Columns.LockObject); }
			set { SetColumnValue(Columns.LockObject, value); }
		}
		  
		[XmlAttribute("Transaction")]
		[Bindable(true)]
		public Guid Transaction 
		{
			get { return GetColumnValue<Guid>(Columns.Transaction); }
			set { SetColumnValue(Columns.Transaction, value); }
		}
		  
		[XmlAttribute("ActivationDate")]
		[Bindable(true)]
		public DateTime? ActivationDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.ActivationDate); }
			set { SetColumnValue(Columns.ActivationDate, value); }
		}
		  
		[XmlAttribute("UserInfo")]
		[Bindable(true)]
		public string UserInfo 
		{
			get { return GetColumnValue<string>(Columns.UserInfo); }
			set { SetColumnValue(Columns.UserInfo, value); }
		}
		  
		[XmlAttribute("LastCall")]
		[Bindable(true)]
		public DateTime? LastCall 
		{
			get { return GetColumnValue<DateTime?>(Columns.LastCall); }
			set { SetColumnValue(Columns.LastCall, value); }
		}
		  
		[XmlAttribute("NextCall")]
		[Bindable(true)]
		public DateTime? NextCall 
		{
			get { return GetColumnValue<DateTime?>(Columns.NextCall); }
			set { SetColumnValue(Columns.NextCall, value); }
		}
		  
		[XmlAttribute("Ultimatum")]
		[Bindable(true)]
		public int Ultimatum 
		{
			get { return GetColumnValue<int>(Columns.Ultimatum); }
			set { SetColumnValue(Columns.Ultimatum, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varLockId,Guid varLockObject,Guid varTransaction,DateTime? varActivationDate,string varUserInfo,DateTime? varLastCall,DateTime? varNextCall,int varUltimatum)
		{
			LockX item = new LockX();
			
			item.LockId = varLockId;
			
			item.LockObject = varLockObject;
			
			item.Transaction = varTransaction;
			
			item.ActivationDate = varActivationDate;
			
			item.UserInfo = varUserInfo;
			
			item.LastCall = varLastCall;
			
			item.NextCall = varNextCall;
			
			item.Ultimatum = varUltimatum;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varLockId,Guid varLockObject,Guid varTransaction,DateTime? varActivationDate,string varUserInfo,DateTime? varLastCall,DateTime? varNextCall,int varUltimatum)
		{
			LockX item = new LockX();
			
				item.LockId = varLockId;
			
				item.LockObject = varLockObject;
			
				item.Transaction = varTransaction;
			
				item.ActivationDate = varActivationDate;
			
				item.UserInfo = varUserInfo;
			
				item.LastCall = varLastCall;
			
				item.NextCall = varNextCall;
			
				item.Ultimatum = varUltimatum;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn LockIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn LockObjectColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn TransactionColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn ActivationDateColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn UserInfoColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn LastCallColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn NextCallColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn UltimatumColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string LockId = @"LockId";
			 public static string LockObject = @"LockObject";
			 public static string Transaction = @"Transaction";
			 public static string ActivationDate = @"ActivationDate";
			 public static string UserInfo = @"UserInfo";
			 public static string LastCall = @"LastCall";
			 public static string NextCall = @"NextCall";
			 public static string Ultimatum = @"Ultimatum";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
